home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #3 / Amiga Plus CD - 2002 - No. 03.iso / AmigaPlus / Tools / Development / stunnel-4.04 / _src / src / common.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-01-01  |  6.4 KB  |  260 lines

  1. /*
  2.  *   stunnel       Universal SSL tunnel
  3.  *   Copyright (c) 1998-2003 Michal Trojnara <Michal.Trojnara@mirt.net>
  4.  *                 All Rights Reserved
  5.  *
  6.  *   This program is free software; you can redistribute it and/or modify
  7.  *   it under the terms of the GNU General Public License as published by
  8.  *   the Free Software Foundation; either version 2 of the License, or
  9.  *   (at your option) any later version.
  10.  *
  11.  *   This program is distributed in the hope that it will be useful,
  12.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *   GNU General Public License for more details.
  15.  *
  16.  *   You should have received a copy of the GNU General Public License
  17.  *   along with this program; if not, write to the Free Software
  18.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #ifndef COMMON_H
  22. #define COMMON_H
  23.  
  24. /* For FormatGuard */
  25. /* #define __NO_FORMATGUARD_ */
  26.  
  27. #ifndef VERSION
  28. #define VERSION "4.04"
  29. #endif
  30.  
  31. #ifndef USE_WIN32
  32.  
  33. /* POSIX threads */
  34. #if HAVE_PTHREAD_H && HAVE_LIBPTHREAD
  35. #define USE_PTHREAD
  36. #define THREADS
  37. #define _REENTRANT
  38. #define _THREAD_SAFE
  39. #else
  40. #define USE_FORK
  41. #endif
  42.  
  43. /* TCP wrapper */
  44. #if HAVE_TCPD_H && HAVE_LIBWRAP
  45. #define USE_LIBWRAP
  46. #endif
  47.  
  48. #endif /* !USE_WIN32 */
  49.  
  50. /* Must be included before sys/stat.h for Ultrix */
  51. #include <sys/types.h>   /* u_short, u_long */
  52.  
  53. /* General headers */
  54. #include <stdio.h>
  55. #include <errno.h>
  56. #include <stdlib.h>
  57. #include <stdarg.h>      /* va_ */
  58. #include <string.h>
  59. #include <ctype.h>       /* isalnum */
  60. #include <time.h>
  61. #include <sys/stat.h>    /* stat */
  62.  
  63. #if defined (USE_WIN32) || defined (__vms)
  64. #define LOG_EMERG       0
  65. #define LOG_ALERT       1
  66. #define LOG_CRIT        2
  67. #define LOG_ERR         3
  68. #define LOG_WARNING     4
  69. #define LOG_NOTICE      5
  70. #define LOG_INFO        6
  71. #define LOG_DEBUG       7
  72. #endif /* defined (USE_WIN32) || defined (__vms) */
  73.  
  74. #ifdef USE_WIN32
  75.  
  76. #ifdef __MINGW32__
  77. #define HOST "x86-pc-mingw32-gnu"
  78. #else
  79. #define HOST "x86-pc-unknown"
  80. #endif
  81.  
  82. typedef unsigned char u8;
  83. typedef unsigned short u16;
  84. typedef unsigned long u32;
  85.  
  86. #define HAVE_VSNPRINTF
  87. #define vsnprintf _vsnprintf
  88. /*  Already defined for mingw, perhaps others
  89. int _vsnprintf(char *, int, char *, ...);
  90. */
  91. #define strcasecmp stricmp
  92.  
  93. #define exit(c) exit_stunnel(c)
  94.  
  95. #define get_last_socket_error() WSAGetLastError()
  96. #define get_last_error()        GetLastError()
  97. #define readsocket(s,b,n)       recv((s),(b),(n),0)
  98. #define writesocket(s,b,n)      send((s),(b),(n),0)
  99.  
  100. #define __USE_W32_SOCKETS
  101.  
  102. /* #define FD_SETSIZE 4096 */
  103. /* #define Win32_Winsock */
  104. #include <windows.h>
  105.  
  106. #define ECONNRESET WSAECONNRESET
  107. #define ENOTSOCK WSAENOTSOCK
  108. #define ENOPROTOOPT WSAENOPROTOOPT
  109. #define EINPROGRESS WSAEINPROGRESS
  110. #define EWOULDBLOCK WSAEWOULDBLOCK
  111. #define EISCONN WSAEISCONN
  112. #undef EINVAL
  113. #define EINVAL WSAEINVAL
  114.  
  115. #define NO_IDEA
  116. #define OPENSSL_NO_IDEA
  117.  
  118. #else /* USE_WIN32 */
  119.  
  120. #if SIZEOF_UNSIGNED_CHAR == 1
  121. typedef unsigned char u8;
  122. #endif
  123.  
  124. #if SIZEOF_UNSIGNED_SHORT == 2
  125. typedef unsigned short u16;
  126. #else
  127. typedef unsigned int u16;
  128. #endif
  129.  
  130. #if SIZEOF_UNSIGNED_INT == 4
  131. typedef unsigned int u32;
  132. #else
  133. typedef unsigned long u32;
  134. #endif
  135.  
  136. #define get_last_socket_error() errno
  137. #define get_last_error()        errno
  138. #define readsocket(s,b,n)       read((s),(b),(n))
  139. #define writesocket(s,b,n)      write((s),(b),(n))
  140. #define closesocket(s)          close(s)
  141. #define ioctlsocket(a,b,c)      ioctl((a),(b),(c))
  142.  
  143.     /* OpenVMS compatibility */
  144. #ifdef __vms
  145. #define libdir "__NA__"
  146. #define PIDFILE "SYS$LOGIN:STUNNEL.PID"
  147. #ifdef __alpha
  148. #define HOST "alpha-openvms"
  149. #else
  150. #define HOST "vax-openvms"
  151. #endif
  152. #include <inet.h>
  153. #include <unistd.h>
  154. #else   /* __vms */
  155. #include <syslog.h>
  156. #endif  /* __vms */
  157.  
  158.     /* Unix-specific headers */
  159. #include <signal.h>      /* signal */
  160. #include <sys/wait.h>    /* wait */
  161. #ifdef HAVE_SYS_RESOURCE_H
  162. #include <sys/resource.h> /* getrlimit */
  163. #endif
  164. #ifdef HAVE_UNISTD_H
  165. #include <unistd.h>      /* getpid, fork, execvp, exit */
  166. #endif
  167. #ifdef HAVE_STROPTS_H
  168. #include <stropts.h>
  169. #endif
  170. #ifdef HAVE_SYS_SELECT_H
  171. #include <sys/select.h>  /* for aix */
  172. #endif
  173. #ifdef HAVE_SYS_FILIO_H
  174. #include <sys/filio.h>   /* for FIONBIO */
  175. #endif
  176. #include <pwd.h>
  177. #ifdef HAVE_SETGROUPS
  178. #include <grp.h>
  179. #endif
  180. #ifdef __BEOS__
  181. #include <posix/grp.h>
  182. #endif
  183. #include <fcntl.h>
  184.  
  185.     /* Networking headers */
  186. #include <netinet/in.h>  /* struct sockaddr_in */
  187. #include <sys/socket.h>  /* getpeername */
  188. #include <arpa/inet.h>   /* inet_ntoa */
  189. #include <sys/time.h>    /* select */
  190. #include <sys/ioctl.h>   /* ioctl */
  191. #include <netinet/tcp.h>
  192. #include <netdb.h>
  193. #ifndef INADDR_ANY
  194. #define INADDR_ANY       (u32)0x00000000
  195. #endif
  196. #ifndef INADDR_LOOPBACK
  197. #define INADDR_LOOPBACK  (u32)0x7F000001
  198. #endif
  199.  
  200. #if defined(HAVE_WAITPID)
  201. /* For SYSV systems */
  202. #define wait_for_pid(a, b, c) waitpid((a), (b), (c))
  203. #define HAVE_WAIT_FOR_PID 1
  204. #elif defined(HAVE_WAIT4)
  205. /* For BSD systems */
  206. #define wait_for_pid(a, b, c) wait4((a), (b), (c), NULL)
  207. #define HAVE_WAIT_FOR_PID 1
  208. #endif
  209.  
  210. /* SunOS 4 */
  211. #if defined(sun) && !defined(__svr4__) && !defined(__SVR4)
  212. #define atexit(a) on_exit((a), NULL)
  213. extern int sys_nerr;
  214. extern char *sys_errlist[];
  215. #define strerror(num) ((num)==0 ? "No error" : \
  216.     ((num)>=sys_nerr ? "Unknown error" : sys_errlist[num]))
  217. #endif /* SunOS 4 */
  218.  
  219. #endif /* USE_WIN32 */
  220.  
  221. /* OpenSSL headers */
  222. #ifdef HAVE_OPENSSL
  223. #include <openssl/lhash.h>
  224. #include <openssl/ssl.h>
  225. #include <openssl/err.h>
  226. #include <openssl/crypto.h> /* for CRYPTO_* and SSLeay_version */
  227. #include <openssl/rand.h>
  228. #else
  229. #include <lhash.h>
  230. #include <ssl.h>
  231. #include <err.h>
  232. #include <crypto.h> /* for CRYPTO_* and SSLeay_version */
  233. #endif
  234.  
  235. /* I/O buffer size */
  236. #define BUFFSIZE 16384
  237.  
  238. /* Length of strings (including the terminating '\0' character) */
  239. #define STRLEN       1024
  240.  
  241. /* How many bytes of random input to read from files for PRNG */
  242. /* OpenSSL likes at least 128 bits, so 64 bytes seems plenty. */
  243. #define RANDOM_BYTES 64
  244.  
  245. /* Safe copy for strings declarated as char[STRLEN] */
  246. #define safecopy(dst, src) \
  247.     (dst[STRLEN-1]='\0', strncpy((dst), (src), STRLEN-1))
  248. #define safeconcat(dst, src) \
  249.     (dst[STRLEN-1]='\0', strncat((dst), (src), STRLEN-strlen(dst)-1))
  250. /* change all non-printable characters to '.' */
  251. #define safestring(s) \
  252.     do {char *p; for(p=(s); *p; p++) if(!isprint((int)*p)) *p='.';} while(0)
  253. /* change all unsafe characters to '.' */
  254. #define safename(s) \
  255.     do {char *p; for(p=(s); *p; p++) if(!isalnum((int)*p)) *p='.';} while(0)
  256.  
  257. #endif /* defined COMMON_H */
  258.  
  259. /* End of common.h */
  260.